home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Program: alarm.c
- Author: A. Michael Ferris
- Date: 10/13/88
- Function:
-
- Provide a method for popup reminders to the display screen
- while other applications execute.
-
- This program uses the Vio popup routines to steal the video
- display and show a short reminder. It also contains some
- primative examples of manipulating the display screen using
- Vio calls.
-
- Usage: detach alarm hh mm [any message up to 70 chars]
-
- Notes:
-
- To compile with MSC 5.10 - cl -Lp -G2 alarm.c
-
- */
-
- #define INCL_BASE
- #define INCL_SUB
- #include <os2.h>
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdarg.h>
- #include <malloc.h>
-
-
- /*
-
- Character mode based definitions and global variable for OS/2 1.0
-
- amf 01/27/88
-
- */
-
- /*
- Screen Color Definitions for EGA/CGA/VGA display adapters in
- color text mode
- */
-
- #define BLACK 0
- #define BLUE 1
- #define GREEN 2
- #define CYAN 3
- #define RED 4
- #define MAGENTA 5
- #define BROWN 6
- #define WHITE 7
-
- #define BRIGHT 8 /* High Intensity */
-
- /* Macro to set a char to the video attributes desired */
-
- #define attr(BACK,FORE) (BACK << 4) | (FORE)
-
- /* Default to bright white on blue */
-
- UCHAR curattr = attr(BLUE,WHITE+BRIGHT);
-
- USHORT oldcol,oldrow; /* Where cursor was when we started */
- USHORT curcol, currow; /* Current Row and Column */
- USHORT curback = BLUE; /* Default background is blue */
- USHORT curfore = WHITE + BRIGHT; /* Default foreground */
- UCHAR space = ' ';
-
- UCHAR ESCAPE[]="Press ESC to continue";
-
- void main(argc, argv)
- UINT argc;
- UCHAR **argv;
- {
- USHORT fWait = VP_WAIT | VP_OPAQUE;
- UCHAR ch,*message;
- DATETIME dateTime;
- USHORT i;
- USHORT handtype, flagword;
-
- /* Verify that we are a detaching the process */
- DosQHandType(0,(unsigned far *)&handtype,
- (unsigned far *)&flagword);
- if ((flagword & 1) | (flagword & 2))
- {
- VioPopUp(&fWait,0);
- cls();
- drawbox(0,0,10,79);
- curattr=attr(BLACK,WHITE);
- VioWrtNAttr(&curattr,80*15,11,0,0);
- curattr = attr(BLUE,WHITE+BRIGHT);
- center(4,"Alarm must run as a detached process");
- center(6,ESCAPE);
- DosBeep(400,100);
- getkey(27);
- VioEndPopUp(0);
- DosExit(1,1);
- }
-
- if (argc < 3) /* Check to see that time is on command line */
- {
- VioPopUp(&fWait,0);
- cls();
- drawbox(0,0,10,79);
- curattr=attr(BLACK,WHITE);
- VioWrtNAttr(&curattr,80*15,11,0,0);
- curattr = attr(BLUE,WHITE+BRIGHT);
- center(4,"Usage: detach alarm hh mm [message]");
- center(6,ESCAPE);
- DosBeep(400,100);
- getkey(27);
- VioEndPopUp(0);
- DosExit(1,1);
- }
-
- while (!(dateTime.hours == atoi(argv[1]) &&
- dateTime.minutes == atoi(argv[2])))
- {
- DosGetDateTime(&dateTime);
- DosSleep(1000L);
- }
-
- message = malloc(81);
- VioPopUp(&fWait, 0); /* Creates a pop-up screen */
- cls();
- drawbox(0,0,10,79);
- curattr=attr(BLACK,WHITE);
- VioWrtNAttr(&curattr,80*15,11,0,0);
- message[0] = 0;
- curattr = attr(BLUE,WHITE+BRIGHT);
- center(1,"Alarm Version 1.1 - Reminder");
- sprintf(message,"Time: %02d:%02d",atoi(argv[1]), atoi(argv[2]));
- center(3, message);
- message[0] = 0;
- if (argc > 3)
- {
- for (i = 3; i < argc; i++)
- {
- message = strcat(message, argv[i]);
- message = strcat(message, " ");
- }
- }
- curattr = attr(BLUE,BROWN+BRIGHT);
- center(6,message);
- curattr = attr(BLUE,WHITE+BRIGHT);
- center(9, ESCAPE);
- for (i = 0 ; i < 3 ; i++)
- DosBeep(400,100);
- getkey(27);
- VioEndPopUp(0); /* Ends the pop-up screen */
- return;
- }
-
-
- drawbox(frow,fcol,trow,tcol) /* Draw box */
- short frow,fcol,trow,tcol;
- {
- static UCHAR uleft = 201;
- static UCHAR uright = 187;
- static UCHAR lleft = 200;
- static UCHAR lright = 188;
- static UCHAR horiz = 205;
- static UCHAR vert = 186;
- static UCHAR ljoin = 204;
- static UCHAR rjoin = 185;
-
- USHORT i;
-
- VioWrtNChar(&horiz, tcol-fcol, frow, fcol, 0);
- VioWrtNChar(&horiz, tcol-fcol, trow, fcol, 0);
- for (i = frow; i < trow; i++)
- {
- VioWrtNChar(&vert,1,i,fcol,0);
- VioWrtNChar(&vert,1,i,tcol,0);
- }
- VioWrtNChar(&uleft,1,frow,fcol,0);
- VioWrtNChar(&uright,1,frow,tcol,0);
- VioWrtNChar(&lleft,1,trow,fcol,0);
- VioWrtNChar(&lright,1,trow,tcol,0);
- }
-
- cls() /* Clear the screen with current attributes */
- {
- UCHAR buff[2];
-
- buff[0] = ' ';
- buff[1] = curattr;
- VioScrollUp(0, 0, -1, -1, -1, (char far *) buff, 0);
- }
-
- gotoxy(row, col) /* Position cursor to row and col */
- USHORT row, col;
- {
- if (row > 24)
- row = 24;
- else if (row < 0) row = 0;
- if (col > 79)
- col = 79;
- else if (col < 0) col = 0;
- VioSetCurPos(row, col, 0);
- currow = row; /* Set current row and column */
- curcol = col;
- }
-
- center(row, string) /* Center a string on a row */
- USHORT row;
- UCHAR *string;
- {
- USHORT col;
-
- col = (80 - strlen(string)) / 2;
- gotoxy(row, col);
- VioWrtCharStrAtt((char far *) string, strlen(string), currow, curcol,
- &curattr, 0);
- curcol += strlen(string); /* Set cursor to last char of string +1 */
- gotoxy(currow,curcol);
- }
-
- vioprintf(fmt) /* Simulate printf function for VIO OS/2 handler */
- UCHAR *fmt; /* Does not parse newlines etc. */
- {
- UCHAR *string; /* Storage for the formatted string */
-
- va_list arg_ptr;
- va_start(arg_ptr, fmt);
- gotoxy(currow,curcol);
- string = malloc(128);
- vsprintf(string, fmt, arg_ptr);
- va_end(arg_ptr);
- VioWrtCharStrAtt((char far *) string, strlen(string),
- currow, curcol, &curattr, 0);
- curcol += strlen(string);
- gotoxy(currow,curcol);
- free(string);
- }
-
- getkey(UCHAR key)
- {
- UCHAR ch;
-
- while ((ch = getch()) != key);
- }